package se.webbzon.boltzmann.minigame.animation;

import se.webbzon.boltzmann.minigame.sandbox.DefaultSandBoxAnimation;
import se.webbzon.boltzmann.minigame.sandbox.SandBoxAnimatable;

public class FadeAnimation extends DefaultSandBoxAnimation {
	
	// The original transparency of the picture
	private float originalAlpha;
	
	// The duration and remaining time
	private final int duration;
	private int remaining;
	
	/*============================================================
	Constructors
	============================================================*/
	
	public FadeAnimation(int duration) {
		this.duration = duration;
		remaining = duration;
	}
	
	/*============================================================
	Public Methods
	============================================================*/

	@Override public void onStepEnd(SandBoxAnimatable picture) {
		if (duration == remaining)
			originalAlpha = picture.getTransparency();
		if (remaining > 0) {
			remaining--;
			float p = remaining / (float) duration;
			picture.setTransparency(p * originalAlpha);
		} else 
			notifyComplete();
	}

}
